package com.cocolove2.cocodialogdemo;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Toast;

import com.cocolove2.library_cocodialog.animations.Attention.Tada;
import com.cocolove2.library_cocodialog.animations.FadeExit.FadeExit;
import com.cocolove2.library_cocodialog.animations.FallEnter.FallEnter;
import com.cocolove2.library_cocodialog.animations.ZoomExit.ZoomOutTopExit;
import com.cocolove2.library_cocodialog.animations.slideEnter.SlideBottomEnter;
import com.cocolove2.library_cocodialog.animations.slideExit.SlideBottomExit;
import com.cocolove2.library_cocodialog.dialogs.ActionSheetDialog;
import com.cocolove2.library_cocodialog.dialogs.MaterialCocoDialog;
import com.cocolove2.library_cocodialog.dialogs.NormalCocoDialog;
import com.cocolove2.library_cocodialog.dialogs.NormalListCocoDialog;
import com.cocolove2.library_cocodialog.dialogs.NormalListCocoPop;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    final String content = "欢迎使用COCODIALOG,祝您开发愉快!";
    AnimationSet inAnima;
    AnimationSet outAnima;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        inAnima = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.modal_in);
        outAnima = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.modal_out);

    }


    NormalCocoDialog mdialog;

    private void showDialog1() {
        if (mdialog == null)
            mdialog = new NormalCocoDialog(this);
        mdialog.setMessage(content)
                .setMessageGravity(Gravity.CENTER)
                .setTitleStr("提示")
                .setTitleTextSize(18)
                .setMessagePadding(16, 1, 16, 1)
                .setTitleGravity(Gravity.CENTER)
                .setBtnPressColor(getResources().getColor(android.R.color.holo_green_light))
                .setTitleLineColor(getResources().getColor(android.R.color.holo_red_dark))
                .setTitleTextColor(getResources().getColor(android.R.color.holo_red_dark))
                .setPositiveButton("确定", 0, null)
                .setNegativeButton("取消", 0, null)
                .setNeturalButton("继续", 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this, which + "#" + "继续", Toast.LENGTH_LONG).show();
                    }
                }).setAnimation(inAnima, outAnima)
                .setCornerRadius(5)
                .show();
    }


    private void showDialog2() {
        MaterialCocoDialog mMaterialCocoDialog = new MaterialCocoDialog(this);
        mMaterialCocoDialog.setMessage(content)
                .setMessageGravity(Gravity.CENTER)
                .setTitleStr("提示")
//                .setTitleTextSize(18)
//                .setTitleGravity(Gravity.CENTER)
                .setMessagePadding(16, 0, 16, 0)
                .setPositiveButton("确定", 0, null)
                .setNegativeButton("取消", 0, null)
                .setBtnPressColor(getResources().getColor(android.R.color.holo_green_light))
                .setNeturalButton("继续", 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this, which + "#" + "继续", Toast.LENGTH_LONG).show();
                    }
                })
                .setAnimation(inAnima, outAnima)
                .setAnimator(new Tada(), new ZoomOutTopExit())
                .setCornerRadius(5)
                .show();
    }

    private void showDialog3() {
        final String[] mStringItems = {"收藏", "下载", "分享", "删除", "歌手", "专辑"};
        NormalListCocoDialog dialog = new NormalListCocoDialog(this);
        dialog.setTitle("请选择")
                .setItems(mStringItems, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        MainActivity.this.finish();
                        Toast.makeText(MainActivity.this, mStringItems[which], Toast.LENGTH_LONG).show();
                    }
                })
                .setItemTextSize(16)
                .setCornerRadius(5)
                .setAnimation(inAnima, outAnima);
        dialog.show();
    }

    private void showDialog4() {
        final String[] mStringItems = {"收藏", "下载", "分享", "删除", "歌手", "专辑"};
        ActionSheetDialog dialog = new ActionSheetDialog(this);
        dialog.setTitle("请选择")
                .setItems(mStringItems, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this, mStringItems[which], Toast.LENGTH_LONG).show();
                    }
                })
                .setItemTextSize(16)
                .setCornerRadius(5)
                .setAnimator(new SlideBottomEnter(), new SlideBottomExit());
        dialog.show();
    }

    private void showPop5() {
        final String[] mStringItems = {"收藏", "下载", "分享", "删除"};

        NormalListCocoPop pop = new NormalListCocoPop(this);
        pop.setItems(mStringItems, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, mStringItems[which], Toast.LENGTH_LONG).show();
            }
        })
                .setItemTextSize(16).setLvWidthAndHeight(200, 0);


        Button button = (Button) findViewById(R.id.main_dialog_btn_5);
        pop.showAsLocation(button, Gravity.BOTTOM, -20.0f, 0);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.main_dialog_btn_1:
                showDialog1();
                break;
            case R.id.main_dialog_btn_2:
                showDialog2();
                break;
            case R.id.main_dialog_btn_3:
                showDialog3();
                break;
            case R.id.main_dialog_btn_4:
                showDialog4();
                break;
            case R.id.main_dialog_btn_5:
                showPop5();
                break;
        }
    }
}
